const app = getApp();
Page({
  data: {
 
  },
  onLoad(options) {
  
  },
  onShow() {
    let _this = this 
    wx.getStorage({
      key: 'user',
      success (res) {
        let user = res.data
        if(user) {
          console.log(user);
          app.globalData.user = user
          _this.setData({
            user
          })
        }else {
          _this._login()
        }
      },fail(ret) {
        _this._login()
      }
    })
  },
  _login() {
  let _this = this 
      wx.showModal({
        title: '提示',
        content: '您当前没有登陆，是否去登录？',
        success (res) {
          if (res.confirm) {
            _this.toLogin()
          } else if (res.cancel) {
            wx.switchTab({
              url: "../index/index",
            });
          }
        }
      })
  },
  toAccount: function(e) {
    wx.navigateTo({
      url: "../account/account",
    });
  },
  toCollect: function(e) {
    wx.navigateTo({
      url: "../collection/collection",
    });
  },
  toSuggest: function(e) {
    wx.navigateTo({
      url: "../suggest/suggest",
    });
  },
  toRelease: function(e) {
    wx.navigateTo({
      url: "../myrelease/myrelease",
    });
  },
  toLogin: function (e) {
    wx.clearStorageSync('user')
    app.globalData ={}
    this.setData({
      user:{}
    })
    console.log(app.globalData);
    
    wx.navigateTo({
      url: "../login/login",
    });
  },
  toAbout: function (e) {
    wx.navigateTo({
      url: "../about/about"
    });
  },
  
})
